package disanzifu;

import java.util.Random;
import java.util.Scanner;

/**
 * 一，需求
 * 一直正确的用户名和密码，请登录程序模拟用户登录
 * 并且给三次机会，登录之后给出相应的提示
 *
 */
public class String3 {
    public static void main(String[] args) {
        String usernamr ="zhangqi";
        String pw ="123456";
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入用户名");
            String inputname = scanner.next();
            System.out.println("请输入密码");
            String inputpw = scanner.next();
            String computerCode =String3.yanzheng();
            System.out.println("电脑产生的验证码是："+computerCode);
            System.out.println("请输入验证码");
            String inputcode1= scanner.next();

            while (!inputcode1.equals(computerCode)){
                Scanner scanner1 = new Scanner(System.in);
                System.out.println("验证码错误，请重新输入");
                inputcode1 = scanner1.next();
            }



            if (inputname.equals(usernamr) &&inputpw.equals(pw)){
                System.out.println("登录成功");
                break;
            }else {
                if (i==2){
                    System.out.println("此账户已被锁定，请联系管理员");
                }else{
                    System.out.println("账户或密码错误，你还剩下"+(2-i)+"次机会");
                }
            }
        }
    }
    public static String yanzheng(){
        char[] code ={'a','b','c','A','B','C','1','2','3','#'};
        Random random =new Random();
        String res ="";
        for (int i = 0; i < 4; i++) {
            int index =random.nextInt(code.length);
            res+=code[index];
        }
        return res;
    }
}
